$(function() {
		initPager();
	});

	function initPager(){
		$("#Pagination").pagination(totalResult, {
            callback: function(new_page_index, pagination_container){
            	var oldLocation = location.href;
            	var pa = "currentPage=" + (new_page_index+1);
        		var shoC = "showCount=" + showCount;
            	var index = oldLocation.lastIndexOf("?");
            	if (index == -1){
            		location.href = oldLocation + "?" + pa + "&" + shoC;
            	}else if (oldLocation.indexOf("currentPage") == -1){
            		location.href = oldLocation + "&" + pa;
            	}else if (oldLocation.indexOf("showCount") == -1){
            		location.href = oldLocation + "&" + shoC;
            	}else{
            		var temp = oldLocation.replace(/currentPage=\d+/, pa);
					var newLocation = temp.replace(/showCount=\d+/, shoC);
            		location.href = newLocation;
            	}
            	return false;
            },
            items_per_page:showCount, 
            load_first_page:false,
            prev_text:'上一页',
            next_text:'下一页',
            ellipse_text:'...',
            num_edge_entries:1,
            num_display_entries:5,
            current_page:currentPage
        });
	}
	/*编辑*/
	function type_edit(obj,id,w,h){
		var edit_page = base_path+"/backstage/type-add-pre2?id="+id;
		layer_show("编辑",edit_page,w,h);
	}	
	
		/*添加*/
		function type_add(title,url){
			var index = layer.open({
				type: 2,
				title: title,
				content: url
			});
			layer.full(index);
		}
		/*重置*/
		function type_reset(url){
			window.location = url;
		}
		
		
		/*删除*/
		function type_disable(obj,id){
			layer.confirm('确认删除？', {
				btn: ['确认','取消'], 
				shade: false
			},
			function(){
				$.ajax({
					type : "POST",
					url : base_path+"/backstage/type-disable",
					data : "id=" + id,
					error : function() {
						layer.msg('操作失败', {icon:5,time:1000});
					},
					success : function(msg) {
						layer.msg('已删除 ' + msg.information, {icon:6,time:1000});
						$(obj).parents("body").find(".btn-refresh").click();
					}
				});
			},
			function(){
				layer.msg('未删除', {icon:5,time:1000});
			});	
		}
		/*审核*/
		function shop_enable(obj,id){
			layer.confirm('审核商户？', {
				btn: ['通过','不通过'], 
				shade: false
			},
			function(){
				$.ajax({
					type : "POST",
					url : base_path+"/backstage/shop-enable",
					data : "c_id=" + id,
					error : function() {
						layer.msg('操作失败', {icon:5,time:1000});
					},
					success : function(msg) {
						$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已审核</span>');
						$(obj).remove();
						layer.msg('已审核' + msg.information, {icon:6,time:1000});
					}
				});
			},
			function(){
				layer.msg('未通过', {icon:5,time:1000});
			});	
		}

		/*图片-下架*/
		function product_stop(obj,id){
			layer.confirm('确认要下架吗？',function(index){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_start(this,id)" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
				$(obj).remove();
				layer.msg('已下架!',{icon: 5,time:1000});
			});
		}
		
		$("#select").on("change", function(){
		    if($(this).val() != 0){
		    	$.ajax({
					type : "POST",
					url : base_path+"/backstage/findsecond",
					data : "cCode=" + $(this).val(),
					success : function(msg) {
						msg = JSON.parse(msg);
						var options = "<option value='' selected>中类</option>";
						for(var i=0;i<msg.typeseconds.length;i++){
							options = options + "<option value='"+msg.typeseconds[i].cCode+"' >"+msg.typeseconds[i].cName+"</option>" ; 
							//alert(msg.typeseconds[i].cName);
						}
						$("#select-two").html(options);
						
					}
				});
		    }

		});
